/**
 * 
 */
package saxena.mf.ui.cmd;

import java.util.Scanner;

import saxena.mf.user.User;

/**
 * @author Ankur
 * 
 */
public class Controller {

	public static enum Command {
		register, login,
	}

	private User currentUser = null;

	public void processCMD(String cmdStr) throws Exception {
		String args[] = cmdStr.split(" ");
		Command cmd = Command.valueOf(args[0].toLowerCase());
		switch (cmd) {
		case register:

			try {
				String userName = args[1];
				currentUser = User.registerUser(userName);
				System.out.println("User registered");
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			break;

		case login:

			try {
				String userName = args[1];
				currentUser = User.loginUser(userName);
				System.out.println("loging successful");
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			break;

		default:
			break;
		}
	}

	public static void main(String args[]) throws Exception {
		Scanner scanner = new Scanner(System.in);
		Controller ctr = new Controller();
		do {
			String line = scanner.nextLine();
			if ("quit".equals(line) || "exit".equals(line))
				break;
			ctr.processCMD(line);
		} while (true);
	}
}
